<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>cookieeditor.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_cookieeditor.js.html">cookieeditor.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Displays and edits the value of a cookie.
<a name="line17"></a> * Intended only for debugging.
<a name="line18"></a> */
<a name="line19"></a>goog.provide(&#39;goog.ui.CookieEditor&#39;);
<a name="line20"></a>
<a name="line21"></a>goog.require(&#39;goog.dom&#39;);
<a name="line22"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line23"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line24"></a>goog.require(&#39;goog.net.cookies&#39;);
<a name="line25"></a>goog.require(&#39;goog.string&#39;);
<a name="line26"></a>goog.require(&#39;goog.style&#39;);
<a name="line27"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>
<a name="line31"></a>/**
<a name="line32"></a> * Displays and edits the value of a cookie.
<a name="line33"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
<a name="line34"></a> * @constructor
<a name="line35"></a> * @extends {goog.ui.Component}
<a name="line36"></a> */
<a name="line37"></a>goog.ui.CookieEditor = function(opt_domHelper) {
<a name="line38"></a>  goog.base(this, opt_domHelper);
<a name="line39"></a>};
<a name="line40"></a>goog.inherits(goog.ui.CookieEditor, goog.ui.Component);
<a name="line41"></a>
<a name="line42"></a>
<a name="line43"></a>/**
<a name="line44"></a> * Cookie key.
<a name="line45"></a> * @type {?string}
<a name="line46"></a> * @private
<a name="line47"></a> */
<a name="line48"></a>goog.ui.CookieEditor.prototype.cookieKey_;
<a name="line49"></a>
<a name="line50"></a>
<a name="line51"></a>/**
<a name="line52"></a> * Text area.
<a name="line53"></a> * @type {HTMLTextAreaElement}
<a name="line54"></a> * @private
<a name="line55"></a> */
<a name="line56"></a>goog.ui.CookieEditor.prototype.textAreaElem_;
<a name="line57"></a>
<a name="line58"></a>
<a name="line59"></a>/**
<a name="line60"></a> * Clear button.
<a name="line61"></a> * @type {HTMLButtonElement}
<a name="line62"></a> * @private
<a name="line63"></a> */
<a name="line64"></a>goog.ui.CookieEditor.prototype.clearButtonElem_;
<a name="line65"></a>
<a name="line66"></a>
<a name="line67"></a>/**
<a name="line68"></a> * Invalid value warning text.
<a name="line69"></a> * @type {HTMLSpanElement}
<a name="line70"></a> * @private
<a name="line71"></a> */
<a name="line72"></a>goog.ui.CookieEditor.prototype.valueWarningElem_;
<a name="line73"></a>
<a name="line74"></a>
<a name="line75"></a>/**
<a name="line76"></a> * Update button.
<a name="line77"></a> * @type {HTMLButtonElement}
<a name="line78"></a> * @private
<a name="line79"></a> */
<a name="line80"></a>goog.ui.CookieEditor.prototype.updateButtonElem_;
<a name="line81"></a>
<a name="line82"></a>
<a name="line83"></a>// TODO(user): add combobox for user to select different cookies
<a name="line84"></a>/**
<a name="line85"></a> * Sets the cookie which this component will edit.
<a name="line86"></a> * @param {string} cookieKey Cookie key.
<a name="line87"></a> */
<a name="line88"></a>goog.ui.CookieEditor.prototype.selectCookie = function(cookieKey) {
<a name="line89"></a>  goog.asserts.assert(goog.net.cookies.isValidName(cookieKey));
<a name="line90"></a>  this.cookieKey_ = cookieKey;
<a name="line91"></a>  if (this.textAreaElem_) {
<a name="line92"></a>    this.textAreaElem_.value = goog.net.cookies.get(cookieKey) || &#39;&#39;;
<a name="line93"></a>  }
<a name="line94"></a>};
<a name="line95"></a>
<a name="line96"></a>
<a name="line97"></a>/** @override */
<a name="line98"></a>goog.ui.CookieEditor.prototype.canDecorate = function() {
<a name="line99"></a>  return false;
<a name="line100"></a>};
<a name="line101"></a>
<a name="line102"></a>
<a name="line103"></a>/** @override */
<a name="line104"></a>goog.ui.CookieEditor.prototype.createDom = function() {
<a name="line105"></a>  // Debug-only, so we don&#39;t need i18n.
<a name="line106"></a>  this.clearButtonElem_ = /** @type {HTMLButtonElement} */ (goog.dom.createDom(
<a name="line107"></a>      goog.dom.TagName.BUTTON, /* attributes */ null, &#39;Clear&#39;));
<a name="line108"></a>  this.updateButtonElem_ = /** @type {HTMLButtonElement} */ (goog.dom.createDom(
<a name="line109"></a>      goog.dom.TagName.BUTTON, /* attributes */ null, &#39;Update&#39;));
<a name="line110"></a>  var value = this.cookieKey_ &amp;&amp; goog.net.cookies.get(this.cookieKey_);
<a name="line111"></a>  this.textAreaElem_ = /** @type {HTMLTextAreaElement} */ (goog.dom.createDom(
<a name="line112"></a>      goog.dom.TagName.TEXTAREA, /* attibutes */ null, value || &#39;&#39;));
<a name="line113"></a>  this.valueWarningElem_ = /** @type {HTMLSpanElement} */ (goog.dom.createDom(
<a name="line114"></a>      goog.dom.TagName.SPAN, /* attibutes */ {
<a name="line115"></a>        &#39;style&#39;: &#39;display:none;color:red&#39;
<a name="line116"></a>      }, &#39;Invalid cookie value.&#39;));
<a name="line117"></a>  this.setElementInternal(goog.dom.createDom(goog.dom.TagName.DIV,
<a name="line118"></a>      /* attibutes */ null,
<a name="line119"></a>      this.valueWarningElem_,
<a name="line120"></a>      goog.dom.createDom(goog.dom.TagName.BR),
<a name="line121"></a>      this.textAreaElem_,
<a name="line122"></a>      goog.dom.createDom(goog.dom.TagName.BR),
<a name="line123"></a>      this.clearButtonElem_,
<a name="line124"></a>      this.updateButtonElem_));
<a name="line125"></a>};
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/** @override */
<a name="line129"></a>goog.ui.CookieEditor.prototype.enterDocument = function() {
<a name="line130"></a>  goog.base(this, &#39;enterDocument&#39;);
<a name="line131"></a>  this.getHandler().listen(this.clearButtonElem_,
<a name="line132"></a>      goog.events.EventType.CLICK,
<a name="line133"></a>      this.handleClear_);
<a name="line134"></a>  this.getHandler().listen(this.updateButtonElem_,
<a name="line135"></a>      goog.events.EventType.CLICK,
<a name="line136"></a>      this.handleUpdate_);
<a name="line137"></a>};
<a name="line138"></a>
<a name="line139"></a>
<a name="line140"></a>/**
<a name="line141"></a> * Handles user clicking clear button.
<a name="line142"></a> * @param {!goog.events.Event} e The click event.
<a name="line143"></a> * @private
<a name="line144"></a> */
<a name="line145"></a>goog.ui.CookieEditor.prototype.handleClear_ = function(e) {
<a name="line146"></a>  if (this.cookieKey_) {
<a name="line147"></a>    goog.net.cookies.remove(this.cookieKey_);
<a name="line148"></a>  }
<a name="line149"></a>  this.textAreaElem_.value = &#39;&#39;;
<a name="line150"></a>};
<a name="line151"></a>
<a name="line152"></a>
<a name="line153"></a>/**
<a name="line154"></a> * Handles user clicking update button.
<a name="line155"></a> * @param {!goog.events.Event} e The click event.
<a name="line156"></a> * @private
<a name="line157"></a> */
<a name="line158"></a>goog.ui.CookieEditor.prototype.handleUpdate_ = function(e) {
<a name="line159"></a>  if (this.cookieKey_) {
<a name="line160"></a>    var value = this.textAreaElem_.value;
<a name="line161"></a>    if (value) {
<a name="line162"></a>      // Strip line breaks.
<a name="line163"></a>      value = goog.string.stripNewlines(value);
<a name="line164"></a>    }
<a name="line165"></a>    if (goog.net.cookies.isValidValue(value)) {
<a name="line166"></a>      goog.net.cookies.set(this.cookieKey_, value);
<a name="line167"></a>      goog.style.showElement(this.valueWarningElem_, false);
<a name="line168"></a>    } else {
<a name="line169"></a>      goog.style.showElement(this.valueWarningElem_, true);
<a name="line170"></a>    }
<a name="line171"></a>  }
<a name="line172"></a>};
<a name="line173"></a>
<a name="line174"></a>
<a name="line175"></a>/** @override */
<a name="line176"></a>goog.ui.CookieEditor.prototype.disposeInternal = function() {
<a name="line177"></a>  this.clearButtonElem_ = null;
<a name="line178"></a>  this.cookieKey_ = null;
<a name="line179"></a>  this.textAreaElem_ = null;
<a name="line180"></a>  this.updateButtonElem_ = null;
<a name="line181"></a>  this.valueWarningElem_ = null;
<a name="line182"></a>};
</pre>


</body>
</html>
